package wwy.Controller;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import wwy.Dto.RegisterDto;
import wwy.feign.getUserService;

@RestController
@Tag(name = "注册")
@RefreshScope
public class RegisterController {
    @Resource
    private getUserService serviceInstance;
    @PostMapping("/register")
    @LoadBalanced
    @CircuitBreaker(name="backendA" ,fallbackMethod = "registerFallback")
    public String register(@RequestBody RegisterDto userInfo){
        return serviceInstance.addNewUser(userInfo);
    }
    public String registerFallback(RegisterDto userInfo, Throwable throwable){
        System.out.println(userInfo.getPhone()+"注册失败" + throwable.getMessage());
        return null;
    }

}
